package com.ninth_group.controller;

import com.ninth_group.dto.CityDTO;
import com.ninth_group.exception.city.CityException;
import com.ninth_group.result.R;
import com.ninth_group.service.CityService;
import com.ninth_group.vo.CityVO;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * 城市基本/天气信息信息
 */
@RestController
@RequestMapping("/cities")
public class CityController {
    @Resource
    private CityService cityService;
    @PostMapping
    public R getCityData(@RequestBody CityDTO cityDTO) throws Exception {
        CityVO cityVO = cityService.getCityBaseInfo(cityDTO);
        return R.ok("success", cityVO);
    }

    @ExceptionHandler(CityException.class)
    public R handleCityException(CityException e) {
        return R.error(e.getMessage());
    }
}
